/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package negocio;

import controladores.SupervisorEntidadFacadeLocal;
import entidades.SupervisorEntidad;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Resource;
import javax.ejb.EJB;
import javax.ejb.EJBContext;
import javax.ejb.Stateless;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;
import javax.transaction.HeuristicMixedException;
import javax.transaction.HeuristicRollbackException;
import javax.transaction.NotSupportedException;
import javax.transaction.RollbackException;
import javax.transaction.SystemException;
import javax.transaction.UserTransaction;

/**
 *
 * @author BATAQUERO
 */
@Stateless(mappedName = "SupervisorEntidadEJB")
@TransactionManagement(TransactionManagementType.BEAN)
public class SupervisorEntidadSvr implements SupervisorEntidadInterface{
    @Resource
    private EJBContext context;
    private UserTransaction utx;
    @EJB
    private SupervisorEntidadFacadeLocal supervisorEntidadFacadeLocal;
    
    
    @Override
    public void crear(SupervisorEntidad supervisorEntidad) {
        try{
            utx = context.getUserTransaction();
            utx.begin();
            System.out.println("------------------despues de begin");
            supervisorEntidadFacadeLocal.create(supervisorEntidad);
            utx.commit();
            System.out.println("hace coommit----");
        } catch (RollbackException ex) {
                Logger.getLogger(UsuarioSrv.class.getName()).log(Level.SEVERE, null, ex);
        } catch (HeuristicMixedException ex) {
                Logger.getLogger(UsuarioSrv.class.getName()).log(Level.SEVERE, null, ex);
        } catch (HeuristicRollbackException ex) {
                Logger.getLogger(UsuarioSrv.class.getName()).log(Level.SEVERE, null, ex);
        } catch(NotSupportedException ex) {
            Logger.getLogger(UsuarioSrv.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SecurityException ex) {
            Logger.getLogger(UsuarioSrv.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalStateException ex) {
            Logger.getLogger(UsuarioSrv.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SystemException ex) {
            Logger.getLogger(UsuarioSrv.class.getName()).log(Level.SEVERE, null, ex);
        }
 
    }

    @Override
    public List<SupervisorEntidad> listarSupervisoresEntidad() {
        return supervisorEntidadFacadeLocal.findAll();
    }

    @Override
    public SupervisorEntidad consultarSupervisorEntidad(int supervisorEntidad) {
        return supervisorEntidadFacadeLocal.consultarSupervisorEntidad(supervisorEntidad);
    }

    @Override
    public void actualizarEstadoSupervisorEntidad(SupervisorEntidad supEnt) {
        try{
            System.out.println("entro al svr de entidad   Actualizar-----------------");
            utx = context.getUserTransaction();
            utx.begin();
            supervisorEntidadFacadeLocal.edit(supEnt);
            utx.commit();
        } catch (NotSupportedException ex) {
            Logger.getLogger(SupervisorEntidadSvr.class.getName()).log(Level.SEVERE, null, ex);
        } catch (RollbackException ex) {
            Logger.getLogger(SupervisorEntidadSvr.class.getName()).log(Level.SEVERE, null, ex);
        } catch (HeuristicMixedException ex) {
            Logger.getLogger(SupervisorEntidadSvr.class.getName()).log(Level.SEVERE, null, ex);
        } catch (HeuristicRollbackException ex) {
            Logger.getLogger(SupervisorEntidadSvr.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SecurityException ex) {
            Logger.getLogger(SupervisorEntidadSvr.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalStateException ex) {
            Logger.getLogger(SupervisorEntidadSvr.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SystemException ex) {
            Logger.getLogger(SupervisorEntidadSvr.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    
    
}
